//
//  HomeView.m
//  Koizora
//
//  Created by dlios on 15-6-8.
//  Copyright (c) 2015年 CupCat. All rights reserved.
//

#import "HomeView.h"
#import "ExchangeStarView.h"
#import "ExchangeStarCollectionViewCell.h"
#import "LuckyCollectionViewCell.h"
#import "LuckyTodayView.h"
#import "LuckyTomorrowView.h"
#import "LuckyMonthView.h"

@interface HomeView ()<UICollectionViewDataSource,UICollectionViewDelegate,UIWebViewDelegate>
@property (nonatomic, assign)NSInteger statu;
@end

@implementation HomeView


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.picArr = [NSMutableArray arrayWithObjects:@"白羊座",@"金牛座",@"双子座",@"巨蟹座",@"狮子座",@"处女座",@"天枰座",@"天蝎座",@"射手座",@"摩羯座",@"水瓶座",@"双鱼座", nil];
        self.luckyArr = [NSMutableArray arrayWithObjects:@"今日",@"明日",@"本周", nil];
        self.statu = 0;
        [self createView];
        [self createCollectionView];
        
    }
    return self;
}

- (void)createView
{
    self.image1 = [[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.width / 3.5 , self.frame.size.height / 7, self.frame.size.width / 9 * 4, 60)];
    _image1.backgroundColor = [UIColor cyanColor];
    [self addSubview:_image1];
    _image1.userInteractionEnabled = YES;
    
    self.lable1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
    _lable1.backgroundColor = [UIColor redColor];
    _lable1.text = @"xin";
    _lable1.font = [UIFont systemFontOfSize:20];
    _lable1.textAlignment = 1;
    [_image1 addSubview:_lable1];
    
    self.lable2 = [[UILabel alloc] initWithFrame:CGRectMake(0, 40, 100, 20)];
    _lable2.font = [UIFont systemFontOfSize:15];
    _lable2.text = @"日期";
    _lable2.textAlignment = 1;
    [_image1 addSubview: _lable2];
    
    self.button1 = [UIButton buttonWithType:UIButtonTypeSystem];
    _button1.frame = CGRectMake(102, 5, 30, 30);
    [_button1 setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [_button1.layer setCornerRadius:15];
    [_button1 addTarget:self action:@selector(touch) forControlEvents:UIControlEventTouchUpInside];
    _button1.backgroundColor = [UIColor yellowColor];
    [_image1 addSubview:_button1];
    
    self.image2 = [[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.width / 10, self.frame.size.height / 4, 60, 60)];
    _image2.backgroundColor = [UIColor cyanColor];
    [_image2.layer setCornerRadius:30];
    [self addSubview:_image2];
    
   
    
}
- (void)touch
{
    [self.delegate TouchStatus];
}

- (void)createCollectionView
{
    UICollectionViewFlowLayout *flowlayout = [[UICollectionViewFlowLayout alloc] init];
    flowlayout.itemSize = CGSizeMake(self.frame.size.width / 3, 30);
    flowlayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    flowlayout.minimumLineSpacing = 0;
    flowlayout.minimumInteritemSpacing = 0;
    flowlayout.scrollDirection = UICollectionViewScrollPositionCenteredHorizontally;
    
    
    self.collectionView1 = [[UICollectionView alloc] initWithFrame:CGRectMake(0, self.frame.size.height / 2.6 , self.frame.size.width, 30) collectionViewLayout:flowlayout];
    _collectionView1.backgroundColor = [UIColor whiteColor];
    _collectionView1.delegate = self;
    _collectionView1.dataSource = self;
    [self addSubview:_collectionView1];
    [_collectionView1 registerClass:[LuckyCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    
    self.luckyToday = [[LuckyTodayView alloc] initWithFrame:CGRectMake(0, self.frame.size.height / 2.6 + 30, self.frame.size.width, self.frame.size.height)];
    _luckyToday.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, 500);
    _luckyToday.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"0"]];
    [self addSubview:_luckyToday];
    
    self.luckyTomorrow = [[LuckyTomorrowView alloc] initWithFrame:CGRectMake(0, self.frame.size.height / 2.6 + 30, self.frame.size.width, self.frame.size.height)];
    _luckyTomorrow.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"2"]];
    _luckyTomorrow.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, 500);
    [self addSubview:_luckyTomorrow];
    
    self.luckyMonth = [[LuckyMonthView alloc]initWithFrame:CGRectMake(0, self.frame.size.height / 2.6 + 30, self.frame.size.width, self.frame.size.height)];
    _luckyMonth.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, 620);
    _luckyMonth.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"01"]];
    [self addSubview:_luckyMonth];
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 3;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    LuckyCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    cell.lable1.text = _luckyArr[indexPath.row];
    
    return cell;
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if(collectionView == _collectionView1)
    {
        if(indexPath.item == 0)
        {
            [self bringSubviewToFront:_luckyToday];
            
        } else if (indexPath.item == 1) {
            
            [self bringSubviewToFront:_luckyTomorrow];
            
        } else if (indexPath.item == 2) {
            
            [self bringSubviewToFront:_luckyMonth];
        }
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
